package com.catmiao.spark.rdd.operator.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{HashPartitioner, SparkConf, SparkContext}

/**
 * @title: RDD_Operator_01_transform
 * @projectName spark_study
 * @description: TODO
 * @author ChengMiao
 * @date 2024/2/2 11:48
 */
object RDD_Operator_13_transform {

  def main(args: Array[String]): Unit = {
    val sparkCon = new SparkConf().setMaster("local[*]").setAppName("rdd")

    val sparkContext = new SparkContext(sparkCon)

    // key-value类型
    val rdd = sparkContext.makeRDD(List(1, 2, 3, 4),2)

    // 隐式转换
    val mapRdd: RDD[(Int, Int)] = rdd.map((_, 1))

    /**
     * 根据指定的分区规则 对数据进行重分区
     */
    mapRdd.partitionBy(new HashPartitioner(2)).saveAsTextFile("output")

    sparkContext.stop()
  }

}
